//
//  PayOrderDetailsView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/1/23.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

protocol PayOrderDetailsViewDelegate:NSObjectProtocol {
    func payOrderDetailsViewAction(tag:Int)
}

class PayOrderDetailsView: UIView {
    var delegate:PayOrderDetailsViewDelegate?
    lazy var backImageView:UIImageView = {
        let imageView = UIImageView.init(frame: FRAME_CGFloat(0, 0, 288, 268))
        imageView.center = self.center
        imageView.backgroundColor = RGB(255, 249, 249)
        imageView.layer.borderWidth = 3
        imageView.layer.borderColor = RGB(254, 144, 32).cgColor
        imageView.layer.cornerRadius = 3
        imageView.layer.masksToBounds = true
        imageView.isUserInteractionEnabled = true
        return imageView
    }()
    lazy var leftImageView:UIImageView = {
        let imageView = UIImageView.init(frame: FRAME_CGFloat(10, 76.8, 72, 72))
        imageView.layer.cornerRadius = 3
        imageView.layer.masksToBounds = true
        return imageView
    }()
    lazy var albumLabel:UILabel = {
        let label = UILabel.init(frame: FRAME_CGFloat(136.5, 73.5, 140, 20))
        label.font = Font_Medium(14)
        label.textColor = RGB_Same(53)
        label.textAlignment = .left
        return label
    }()
    lazy var numberLabel:UILabel = {
        let label = UILabel.init(frame: FRAME_CGFloat(136.5, 102.5, 140, 20))
        label.font = Font_Medium(14)
        label.textColor = RGB_Same(53)
        label.textAlignment = .left
        return label
    }()
    lazy var priceLabel:UILabel = {
        let label = UILabel.init(frame: FRAME_CGFloat(136.5, 131.5, 140, 20))
        label.font = Font_Medium(14)
        label.textColor = RGB_Same(53)
        label.textAlignment = .left
        return label
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.isUserInteractionEnabled = true
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.backgroundColor = RGB(0, 0, 0, 0.8)
        self.addSubview(self.backImageView)
        
        let titleLabel = UILabel.init(frame: FRAME_CGFloat(0, 27.5, 288, 24))
        titleLabel.text = "订单详情"
        titleLabel.font = Font_Medium(17)
        titleLabel.textAlignment = .center
        self.backImageView.addSubview(titleLabel)
        
        self.backImageView.addSubview(self.leftImageView)
        self.backImageView.addSubview(self.albumLabel)
        self.backImageView.addSubview(self.numberLabel)
        self.backImageView.addSubview(self.priceLabel)
        
        let albumLabel1 = UILabel.init(frame: FRAME_CGFloat(97, 73.5, 30, 20))
        albumLabel1.text = "专辑"
        albumLabel1.textColor = RGB_Same(53)
        albumLabel1.font = Font_Medium(14)
        albumLabel1.textAlignment = .center
        self.backImageView.addSubview(albumLabel1)
        
        let numberLabel2 = UILabel.init(frame: FRAME_CGFloat(97, 102.5, 30, 20))
        numberLabel2.text = "集数"
        numberLabel2.textColor = RGB_Same(53)
        numberLabel2.font = Font_Medium(14)
        numberLabel2.textAlignment = .center
        self.backImageView.addSubview(numberLabel2)
        
        let priceLabel3 = UILabel.init(frame: FRAME_CGFloat(97, 131.5, 30, 20))
        priceLabel3.text = "价格"
        priceLabel3.textColor = RGB_Same(53)
        priceLabel3.font = Font_Medium(14)
        priceLabel3.textAlignment = .center
        self.backImageView.addSubview(priceLabel3)
        
        let button = UIButton(type: UIButton.ButtonType.custom)
        button.frame = FRAME_CGFloat(260, 10, 15, 15)
        button.addTarget(self, action: #selector(hiddenAction(btn:)), for: .touchUpInside)
        button.setImage(IMAGE(name: "payOrderClose"), for: .normal)
        button.tag = 31
        self.backImageView.addSubview(button)
        
        let buyButton = UIButton(type: UIButton.ButtonType.custom)
        buyButton.frame = FRAME_CGFloat(26.5, 209.5, 235, 37.5)
        buyButton.addTarget(self, action: #selector(hiddenAction(btn:)), for: .touchUpInside)
        buyButton.setTitle("确认购买", for: .normal)
        buyButton.layer.cornerRadius = 18
        buyButton.backgroundColor = RGB(87, 154, 255)
        buyButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 19)
        buyButton.tag = 32
        self.backImageView.addSubview(buyButton)
        
    }
    
    @objc func hiddenAction(btn:UIButton) {
        delegate?.payOrderDetailsViewAction(tag: btn.tag)
    }
    
    func setData(imageStr:String,albumStr:String,numberStr:String,priceStr:String) {
        self.leftImageView.sd_setImage(with: URLSTR(StringIncludeChineseToString(imageStr)), completed: nil)
        self.albumLabel.text = albumStr
        self.numberLabel.text = numberStr
        self.priceLabel.text = priceStr
        
    }

}
